//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "ai\fn_throwSmoke.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_unit","_shell","_moves","_unitPos","_pos","_flare","_direction"];
DEFAULT_PARAM(_unit,0,objNull);

if (AND_ALSO(IS_OBJECT(_unit), (!isNull _unit))) then { 	
	/*
	_stanThrow = ["AwopPercMstpSgthWrflDnon_Start1", "AwopPercMstpSgthWrflDnon_Throw1","AwopPercMstpSgthWrflDnon_End1"];	
	_kneeThrow = ["AwopPknlMstpSgthWrflDnon_Start", "AwopPknlMstpSgthWrflDnon_Throw" ,"AwopPknlMstpSgthWrflDnon_End"];
	_proneThrow= ["AwopPpneMstpSgthWrflDnon_Start", "AwopPpneMstpSgthWrflDnon_Throw" ,"AwopPpneMstpSgthWrflDnon_End"]; 
	*/
	_moves = ["AwopPercMstpSgthWrflDnon_Start1","AwopPknlMstpSgthWrflDnon_Start","AwopPpneMstpSgthWrflDnon_Start"];

	_shell = "SmokeShell";
	_unitPos = unitPos _unit; 

	//Animation
	switch (_unitPos) do {   
		
		case "Auto":
		{	
			_unit playMove (_moves select 1);	
		};

		case "Up":
		{	
			_unit playMove (_moves select 0);	
		};

		case "Middle":
		{	
			_unit playMove (_moves select 1);	
		};
		
		case "Down":
		{	
			_unit playMove (_moves select 2);	
		};
	};	

	sleep 4;
	_direction = direction _unit;		

	// use such bypass as setvelocity does not work in MP
	_pos = position _unit;
	_pos = [(_pos select 0),(_pos select 1),(_pos select 2)+1.5];
	_pos = [_pos, 18, _direction] call FFUNC(relPos3D);
			
	if (alive _unit && canmove _unit) then {	
		_flare = _shell createVehicle _pos;
		TRACE_1("Shell",ARR_2(_flare, position _flare));
	};
};

TRACE("End");
TMFPROFILERSTOP;
